# coding=utf-8
import arcpy

path = r'D:\Test';
arcpy.env.workspace = path
shp = r'D:\Test\YA_RIV_LEVEL6_4326_0717_1.shp'.decode('utf-8')
cs1 = arcpy.da.SearchCursor(shp,['SHAPE@','name','level','flowRiv','flowId','rivid'])

for row1 in cs1:
    flowRiverID = row1[4]
    expression = 'rivId = {}'.format(flowRiverID)
    cs2 = arcpy.da.SearchCursor(shp, ['SHAPE@', 'name', 'level', 'flowRiv', 'flowId', 'rivid'],where_clause=expression)
    for row2 in cs2:
        dis = row2[0].distanceTo(row1[0].lastPoint)
        if(dis > 0.0):
            print row1[1],row1[2],row1[5],'------汇入-------:',row2[1],row2[2],row2[5],'距离:',dis
    cs2.reset()
